package main

import (
	"fmt"
	"reflect"
)

func main() {
	// 对结构体进行反射
	stu := Student {
		Name: "张三",
		Age: 18,
	}

	testReflect(stu)

}

func testReflect(i interface{}) {
	// teypOf
	reType := reflect.TypeOf(i)
	fmt.Println("reType: ", reType)
	fmt.Printf("reType类型: %T \n", reType)


	reValue := reflect.ValueOf(i)
	fmt.Println("reValue: ", reValue)
	fmt.Printf("reValue类型: %T \n", reValue)

	
	//将reValue转成空接口，进行类型断言
	i2 := reValue.Interface()
	n, flag := i2.(Student)
	if flag == true {
		fmt.Printf("学生的名字: %v, 学生的年龄是: %v", n.Name, n.Age)
	}

}

type Student struct{
	Name string
	Age int
}